package ObjectStatic.ObjectStaticExercise001;

/**
 * ClassName:ArrayUtil
 * Package:ObjectStatic
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/19-12:09
 * @Version:v1.0
 */
public class ArrayUtil {
    //私有化构造方法
    //目的：为了不让外界创建他的对象
    private ArrayUtil() {
    }

    //需要定义静态的,方便调用
    public static String printArr(int[] arr) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < arr.length; i++) {
            //i索引 arr[i]元素
            if (i == arr.length - 1) {
                sb.append(arr[i]);
            } else {
                sb.append(arr[i] + ",");
            }
        }
        sb.append("]");
        return sb.toString();
    }

    public static double getAverage(double[] arr) {
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum / arr.length;
    }


}
